package com.itwn.portal.mapper;

import com.itwn.portal.entity.Resource;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import com.itwn.portal.vo.ResourceVo;


import java.util.List;
@Repository
public interface ResourceMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(Resource record);

    Resource selectByPrimaryKey(@Param("id") Integer id);

    List<Resource> selectAll();

    int updateByPrimaryKey(Resource record);

    List<ResourceVo> selectResource(@Param("rname") String name, @Param("tagId") Integer tagId,@Param("num") Integer num,@Param("orders")Integer orders);

    List<ResourceVo> selectByFine(@Param("num") Integer num);

    List<ResourceVo> selectByBuy(@Param("num") Integer num);

    List<ResourceVo> selectByRed(Integer num);

    List<ResourceVo> selectByCons();

    List<ResourceVo> selectMonth(@Param("num") Integer num);

    List<ResourceVo> selectByCollect(@Param("num")Integer num);

    List<ResourceVo> selectBySex(@Param("num") Integer num);

    List<ResourceVo> selectPersonCollect(@Param("uid") Integer uid);

    Integer selectPersonBuyTotalByUid(Integer uid);

    void updateCollectionNumAdd(@Param("rid") Integer rid,@Param("num") Integer num);

    /**
     * 更新投票后的月票数量的一个dao
     * @param rid
     */
    @Update("update t_resource set ticket_num = ticket_num + 1 where id = #{rid}")
    void updateIncrMTicketCount(@Param("rid")Integer rid);

    /**
     * 投红票
     * @param rid
     */
    @Update("update t_resource set red = red + 1 where id = #{rid}")
    void voteRed(@Param("rid")Integer rid);

    /**
     * 投黑票
     * @param rid
     */
    @Update("update t_resource set black = black + 1 where id = #{rid}")
    void voteBlack(@Param("rid")Integer rid);

    /**
     * 查询第一章的id
     * @param rid
     * @return
     */
    @Select("select min(id) from t_section where resource_id = #{rid}")
    int selectFirstSectionId(@Param("rid")Integer rid);
}